interface ServerResponse<T> {
    msg: string,
    data: T,
    code: number
}

Page({
    data: {
        joker: '',
        jokerList: [] as string[]
    },
    onLoad() {
        this.getData()
    },
    getData() {
        wx.showLoading({ title: '数据加载中……' })
        wx.request({
            method: 'GET',
            url: 'https://api-vue-base.itheima.net/api/joke',
            success: (res) => {
                console.log(res.data)
                this.setData({
                    joker: res.data as string
                })
            },
            fail: () => {
                wx.showToast({ title: '请求异常', icon: 'error' })
            },
            complete: () => {
                wx.hideLoading()
            }
        })
    },
    getJokerList() {
        wx.showLoading({ title: '数据加载中……' })
        wx.request<ServerResponse<string[]>>({
            url: 'https://api-vue-base.itheima.net/api/joke/list',
            method: 'GET',
            data:{num:5},//必传参数
            success: (res) => {
                this.setData({
                    jokerList: res.data.data
                })
            },
            fail: () => {
                wx.showToast({ title: '多条数据请求异常', icon: 'error' })
            },
            complete: () => {
                wx.hideLoading()
            }
        })
    }
})